home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / sources / whdload / keyboard.s < prev    next >
Encoding:
Text File  |  2003-06-07  |  3.6 KB  |  151 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    keyboard.s
  3. ;  :Contents.    routine to setup an keyboard handler
  4. ;  :Version.    $Id: keyboard.s 1.9 2003/05/14 23:56:44 wepl Exp $
  5. ;  :History.    30.08.97 extracted from some slave sources
  6. ;        17.11.97 _keyexit2 added
  7. ;        23.12.98 _key_help added
  8. ;        07.10.99 some cosmetic changes, documentation improved
  9. ;        24.10.99 _keycode added
  10. ;        15.05.03 better interrupt acknowledge
  11. ;  :Requires.    _keydebug    byte variable containing rawkey code
  12. ;        _keyexit    byte variable containing rawkey code
  13. ;  :Optional.    _keyexit2    byte variable containing rawkey code
  14. ;        _key_help    function to execute on help pressed
  15. ;        _debug        function to quit with debug
  16. ;        _exit        function to quit
  17. ;        _keycode
  18. ;  :Copyright.    Public Domain
  19. ;  :Language.    68000 Assembler
  20. ;  :Translator.    Barfly 2.9
  21. ;  :To Do.
  22. ;---------------------------------------------------------------------------*
  23. ; this routine setups a keyboard handler, realizing quit and quit-with-debug
  24. ; feature by pressing the appropriate key. the following variables must be
  25. ; defined:
  26. ;    _keyexit
  27. ;    _keydebug
  28. ; the labels should refer to the Slave structure, so user definable quit- and
  29. ; debug-key will be supported
  30. ;
  31. ; the optional variable:
  32. ;    _keyexit2
  33. ; can be used to specify a second quit-key, if a quit by two different keys
  34. ; should be supported
  35. ;
  36. ; the optional function:
  37. ;    _key_help
  38. ; will be called when the 'help' key is pressed, the fuction must return via
  39. ; 'rts' and must not change any registers
  40. ;
  41. ; the optional variable:
  42. ;     _keycode
  43. ; will be filled with the last rawkeycode
  44. ;
  45. ; IN:    -
  46. ; OUT:    -
  47.  
  48. _SetupKeyboard
  49.     ;set the interrupt vector
  50.         pea    (.int,pc)
  51.         move.l    (a7)+,($68)
  52.     ;allow interrupts from the keyboard
  53.         move.b    #CIAICRF_SETCLR|CIAICRF_SP,(ciaicr+_ciaa)
  54.     ;clear all ciaa-interrupts
  55.         tst.b    (ciaicr+_ciaa)
  56.     ;set input mode
  57.         and.b    #~(CIACRAF_SPMODE),(ciacra+_ciaa)
  58.     ;clear ports interrupt
  59.         move.w    #INTF_PORTS,(intreq+_custom)
  60.     ;allow ports interrupt
  61.         move.w    #INTF_SETCLR|INTF_INTEN|INTF_PORTS,(intena+_custom)
  62.         rts
  63.  
  64. .int        movem.l    d0-d1/a0-a1,-(a7)
  65.         lea    (_custom),a0
  66.         lea    (_ciaa),a1
  67.     ;check if keyboard has caused interrupt
  68.         btst    #INTB_PORTS,(intreqr+1,a0)
  69.         beq    .end
  70.         btst    #CIAICRB_SP,(ciaicr,a1)
  71.         beq    .end
  72.     ;read keycode
  73.         move.b    (ciasdr,a1),d0
  74.     ;set output to low and output mode (handshake)
  75.         clr.b    (ciasdr,a1)
  76.         or.b    #CIACRAF_SPMODE,(ciacra,a1)
  77.     ;calculate rawkeycode
  78.         not.b    d0
  79.         ror.b    #1,d0
  80.  
  81.         cmp.b    (_keydebug,pc),d0
  82.         bne    .1
  83.         movem.l    (a7)+,d0-d1/a0-a1
  84.         move.w    (a7),(6,a7)            ;sr
  85.         move.l    (2,a7),(a7)            ;pc
  86.         clr.w    (4,a7)                ;ext.l sr
  87.     IFD _debug
  88.         bra    _debug
  89.     ELSE
  90.         bra    .debug
  91.     ENDC
  92.  
  93. .1        cmp.b    (_keyexit,pc),d0
  94.     IFD _exit
  95.         beq    _exit
  96.     ELSE
  97.         beq    .exit
  98.     ENDC
  99.  
  100.     IFD _keyexit2
  101.         cmp.b    (_keyexit2,pc),d0
  102.     IFD _exit
  103.         beq    _exit
  104.     ELSE
  105.         beq    .exit
  106.     ENDC
  107.     ENDC
  108.  
  109.     IFD _key_help
  110.         cmp.b    #$5f,d0
  111.         bne    .2
  112.         bsr    _key_help
  113. .2
  114.     ENDC
  115.  
  116.     IFD _keycode
  117.         move.l    a0,-(a7)
  118.         lea    (_keycode,pc),a0
  119.         move.b    d0,(a0)
  120.         move.l    (a7)+,a0
  121.     ENDC
  122.  
  123.     ;better would be to use the cia-timer to wait, but we arn't know if
  124.     ;they are otherwise used, so using the rasterbeam
  125.     ;required minimum waiting is 75 µs, one rasterline is 63.5 µs
  126.     ;a loop of 3 results in min=127µs max=190.5µs
  127.         moveq    #3-1,d1
  128. .wait1        move.b    (vhposr,a0),d0
  129. .wait2        cmp.b    (vhposr,a0),d0
  130.         beq    .wait2
  131.         dbf    d1,.wait1
  132.  
  133.     ;set input mode
  134.         and.b    #~(CIACRAF_SPMODE),(ciacra,a1)
  135. .end        move.w    #INTF_PORTS,(intreq,a0)
  136.     ;to avoid timing problems on very fast machines we do another
  137.     ;custom access
  138.         tst.w    (intreqr,a0)
  139.         movem.l    (a7)+,d0-d1/a0-a1
  140.         rte
  141.  
  142.     IFND _exit
  143. .debug        pea    TDREASON_DEBUG.w
  144. .quit        move.l    (_resload,pc),-(a7)
  145.         addq.l    #resload_Abort,(a7)
  146.         rts
  147. .exit        pea    TDREASON_OK.w
  148.         bra    .quit
  149.     ENDC
  150.  
  151.